package com.bit.musicserver.config;

import com.bit.musicserver.Tools.Constat;
import com.bit.musicserver.Tools.ResponseBodyMessage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class LoginInterceptor implements HandlerInterceptor {//注册拦截器

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {
        //1.检查是否登成功
        HttpSession httpSessionsession = request.getSession(false);
        if (httpSessionsession != null && httpSessionsession.getAttribute(Constat.USERINDFO_SESSION_KEY) != null ){
            System.out.println("没有登录");
           // return new ResponseBodyMessage<>(-1,"请登录",false).getData();
            return true;
        }
        return false;
    }
}
